<?php

namespace App\Admin\Actions\Grid;


use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class ProductGroupReset extends RowAction
{
    /**
     * @return string
     */
	protected $title = '<button class="btn btn-primary" style="margin-right: 20px"><i class="fa fa-circle-o-notch"></i> 重新洗牌 </button>';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        set_time_limit(0);
        try {
            $count = app(\App\Services\Compose::class)->start();

            return $this->response()
                ->success('成功：'.$count)
                ->refresh();
        }catch (\Exception $exception){
            dd($exception);
            return $this->response()
                ->error($exception->getMessage())
                ->refresh();
        }




    }

    /**
	 * @return string|array|void
	 */
	public function confirm()
	{
		 return ['確認重新洗牌？', ''];
	}

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }


}
